// https://www.acwing.com/problem/content/907/

#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

struct Compare {
    bool operator()(const pair<int, int>& p1, const pair<int, int>& p2) const {
        return p1.second < p2.second;
    }
};

int main() {
    int n, a, b;
    scanf("%d", &n);
    vector<pair<int, int>> arr(n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &a, &b);
        arr[i] = pair<int, int>(a, b);
    }

    sort(arr.begin(), arr.end(), Compare());
    long end = LONG_MIN;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (arr[i].first > end) {
            cnt++;
            end = arr[i].second;
        }
    }
    printf("%d\n", cnt);
    return 0;
}